﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace WinAppCS
{
	public partial class PaneBase : UserControl
	{
		/// TODO: Understand why this event raises a NullArgumentException...!
		//public delegate void PaneActiveHandler(object sender, EventArgs e);
		//public event PaneActiveHandler PaneActive;

		#region "Constructors & Destructors"
		public PaneBase()
		{
			InitializeComponent();

			SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint |
				 ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true);
	}
		#endregion

		#region "Procedures"
		#endregion

		#region "Properties"
		[Description("The pane caption."),
		Category("Appearance")]
		public PaneCaption CaptionControl
		{
			get { return myCaption; }
		}

		[Description("The pane caption."),
		Category("Appearance")]
		public string Caption
		{
			get { return myCaption.Text; }
			set
			{
				myCaption.Text = value;
			}
		}

		[Description("The active state of the Pane, draws the caption with different gradient colors."),
		Category("Appearance"),
		DefaultValue(false)]
		public bool Active
		{
			get { return myCaption.Active; }
		}
		#endregion

		#region "Event Handlers"
		protected override void OnEnter(EventArgs e)
		{
			base.OnEnter(e);
			myCaption.Active = true;
			//PaneActive(this, EventArgs.Empty);
		}

		protected override void OnLeave(EventArgs e)
		{
			base.OnLeave(e);
			myCaption.Active = false;
		}

		protected override void OnPaint(PaintEventArgs e)
		{
			Rectangle rc = new Rectangle(0, 0, Width - 1, Height - 1);
			rc.Inflate(-DockPadding.All + 1, -DockPadding.All + 1);
			e.Graphics.DrawRectangle(SystemPens.ControlDark, rc);
			base.OnPaint(e);
		}

		protected override void OnResize(EventArgs e)
		{
			base.OnResize(e);

			if (DesignMode == true)
				myCaption.Width = Width;
		}
		#endregion
	}
}
